#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    // 添加一个默认的选项
    ui->radioButton_male->setChecked(true);
    ui->label->setText("您选择的性别为: 男");
    // 禁用 其他 选项
    // checkable 只是能够让按钮不被选中. 仍然是可以响应点击事件的.
    // ui->radioButton_other->setCheckable(false);
    ui->radioButton_other->setEnabled(false);
    // ui->radioButton_other->setDisabled(true);




        // 使用 QButtonGroup 对单选按钮进行分组
        QButtonGroup* group1 = new QButtonGroup(this);
        QButtonGroup* group2 = new QButtonGroup(this);
        QButtonGroup* group3 = new QButtonGroup(this);


        group1->addButton(ui->radioButton);
        group1->addButton(ui->radioButton_2);
        group1->addButton(ui->radioButton_3);

        group2->addButton(ui->radioButton_4);
        group2->addButton(ui->radioButton_5);
        group2->addButton(ui->radioButton_6);

        group3->addButton(ui->radioButton_7);
        group3->addButton(ui->radioButton_8);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_radioButton_clicked(bool checked)
{
    // 一直点会一直触发
    qDebug() << "clicked: " << checked;
}

void Widget::on_radioButton_2_pressed()
{
    qDebug() << "pressed";
}

void Widget::on_radioButton_3_released()
{
    qDebug() << "released";
}

void Widget::on_radioButton_4_toggled(bool checked)
{
    //checked 状态发生改变, 就会触发这个信号：首次点和点击另外的按钮会触发此信号
    qDebug() << "toggled: " << checked;
}
